package com.khotyn.heresy.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.khotyn.heresy.bean.Album;
import com.khotyn.heresy.dao.AlbumDAO;
/**
 * Album DAO iBATIS 实现
 * @author 黄挺
 *
 */
public class AlbumDAOIbatisImpl extends SqlMapClientDaoSupport implements AlbumDAO{
	public Integer getPictureCount(Integer albumID) {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("selectPictureCount",albumID);
	}

	public int updatePictureCount(Album album) {
		return this.getSqlMapClientTemplate().update("updatePictureCount", album);
	}
	
	public Integer insertAlbum(Album album){
		return (Integer) this.getSqlMapClientTemplate().insert("insertAlbum", album);
	}
	
	public void deleteAlbumByID(Album album){
		this.getSqlMapClientTemplate().delete("deleteAlbumByID", album.getAlbumID());
	}

	@SuppressWarnings("unchecked")
	public List<Album> findAllAlbum() {
		List<Album> queryForList = getSqlMapClientTemplate().queryForList("selectAllAlbum");
		return queryForList;
	}

	public int getAlbumCountByUserID(Album album) {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("getAlbumCountByUserID",album.getAlbumID());
	}

	public Album selectAlbumByID(Integer albumID) {
		Album alb=(Album) getSqlMapClientTemplate().queryForObject("selectAlbumByID",albumID);
		return alb;
	}

	@SuppressWarnings("unchecked")
	public List<Album> selectAlbumByUserID(Integer userID) {
		List<Album> queryForList = getSqlMapClientTemplate().queryForList("selectAlbumByUserID", userID);
		return queryForList;
	}

	public int updateAlbumByID(Album album) {
		return this.getSqlMapClientTemplate().update("updateAlbumByID", album);
	}

	public int updateAlbumDescriptionByID(Album album) {
		return this.getSqlMapClientTemplate().update("updateAlbumDescription", album);
	}

	public int updateAlbumNameByID(Album album) {
		return this.getSqlMapClientTemplate().update("updateAlbumName", album);
	}

	@SuppressWarnings("unchecked")
	public int updateEnvelopPicId(Integer albumID, String envelopPicId) {
		Map map = new HashMap();
		map.put("albumID", albumID);
		map.put("envelopPicId", envelopPicId);
		return this.getSqlMapClientTemplate().update("updateEnvelopPicId", map);
	}

	public int updateFlagPermission(Album album) {
		return this.getSqlMapClientTemplate().update("updateFlagPermission", album);
	}

	public int updateFlagSortType(Album album) {
		return this.getSqlMapClientTemplate().update("updateFlagSortType", album);
	}

	@SuppressWarnings("unchecked")
	public List<Album> selectPagedAlbumByUserID(Integer userID, Integer minRow,
			Integer maxRow) {
		Map map = new HashMap();
		map.put("userID", userID);
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		
		return this.getSqlMapClientTemplate().queryForList("selectPagedAlbumByUserID", map);
	}

	public int delteAlbumByUserID(Integer userID) {
		return this.getSqlMapClientTemplate().delete("delteAlbumByUserID", userID);
	}

	@SuppressWarnings("unchecked")
	public Album selectAlbumByNameAndUserId(Integer userID, String albumName) {
		Map map = new HashMap();
		map.put("albumName", albumName);
		map.put("userID", userID);
		return (Album) this.getSqlMapClientTemplate().queryForObject("selectAlbumByNameAndUserId", map);
	}
}
